﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;
public partial class administrator_uc_admin_v_supportonline : WebPageSecurity
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PanelEdit.Visible = false;
            if (!string.IsNullOrEmpty(Request.QueryString["itemid"]))
            {
                LoadDataInfo(int.Parse(Request.QueryString["itemid"].ToString().Trim()));               
            }
        }
    }
    private void LoadDataInfo(int ItemID)
    {
        DataTable dt = new BLL.CmsBLL().SupportOnline_ViewItemByID(ItemID);
        if (dt.Rows.Count > 0)
        {            
            ltSupportID.Text = dt.Rows[0]["SupportID"].ToString();
            hdItemID.Value = dt.Rows[0]["SupportID"].ToString();
            ltDescription.Text = dt.Rows[0]["Description"].ToString();
            ltFullName.Text = dt.Rows[0]["FullName"].ToString();
            ltAddress.Text = dt.Rows[0]["Address"].ToString();
            ltEmail.Text = dt.Rows[0]["Email"].ToString();
            ltPhoneNumber.Text = dt.Rows[0]["PhoneNumber"].ToString();
            ltYahoo.Text = dt.Rows[0]["Yahoo"].ToString();
            ltSortIndex.Text = dt.Rows[0]["SortIndex"].ToString();           
            ltActive.Text = dt.Rows[0]["_Active"].ToString();
        }
        else
            lblMessageView.Text = "Load dữ liệu lỗi!";
    }   
    protected void btnEditItem_Click(object sender, EventArgs e)
    {
        PanelView.Visible = false;
        PanelEdit.Visible = true;    
        LoadDataInfoEdit(int.Parse("0"+hdItemID.Value));     
    }
    private void LoadDataInfoEdit(int ItemID)
    {
        DataTable dt = new BLL.CmsBLL().SupportOnline_ViewItemByID(ItemID);
        if (dt.Rows.Count > 0)
        {            
            txtDescription.Text = dt.Rows[0]["Description"].ToString();
            txtFullName.Text = dt.Rows[0]["FullName"].ToString();
            txtAddress.Text = dt.Rows[0]["Address"].ToString();
            txtEmail.Text = dt.Rows[0]["Email"].ToString();
            txtPhoneNumber.Text = dt.Rows[0]["PhoneNumber"].ToString();
            txtYahoo.Text = dt.Rows[0]["Yahoo"].ToString();
            txtSortIndex.Text = dt.Rows[0]["SortIndex"].ToString();
            rdActive.SelectedValue = dt.Rows[0]["Active"] + "";
        }
        else
            lblMessageEdit.Text = "Load data failt!";
    }      
    protected void lbtUpdateItem_Click(object sender, EventArgs e)
    {
        try
        {
            new CmsBLL().SupportOnline_UpDateItem(int.Parse(hdItemID.Value), txtDescription.Text, txtFullName.Text, txtAddress.Text, txtEmail.Text,txtPhoneNumber.Text, txtYahoo.Text, int.Parse("0" + txtSortIndex.Text.Trim()), int.Parse("0" + rdActive.SelectedValue));
            lblMessageEdit.Text = "Cập nhật thành công!";           
        }
        catch (Exception ex)
        {
            lblMessageEdit.Text = "ERROR! " + ex.Message.ToString();
        }
    }
}